package com.aiton.bamin.changtukepiao.Cdachezuche.DaCheZuCheFragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiton.bamin.changtukepiao.Cdachezuche.QiYeZuChe.ZuChenJiGouYongCheActivity;
import com.aiton.bamin.changtukepiao.Cdachezuche.ZiJiaZuChe.ZiJiaZuCheActivity;
import com.aiton.bamin.changtukepiao.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class MainFragment extends Fragment implements View.OnClickListener
{

    private View mInflate;
    private ImageView mIv_qicheguanjia_back;
    private TextView mTv_oil_price_ninety_seven;
    private TextView mTv_oil_price_ninety_three;
    private TextView mTv_oil_price_ninety;
    private TextView mTv_oil_price_zero;

    public MainFragment()
    {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Inflate the layout for this fragment
        if (mInflate == null)
        {
            mInflate = inflater.inflate(R.layout.fragment_main2, null);
            findViewID();
            setListener();
            initUI();
        }
        //缓存的rootView需要判断是否已经被加过parent， 如果有parent需要从parent删除，要不然会发生这个rootview已经有parent的错误。
        ViewGroup parent = (ViewGroup) mInflate.getParent();
        if (parent != null)
        {
            parent.removeView(mInflate);
        }
        return mInflate;
    }

    private void findViewID()
    {
        mIv_qicheguanjia_back = (ImageView) mInflate.findViewById(R.id.iv_qicheguanjia_back);
        mTv_oil_price_ninety_seven = (TextView) mInflate.findViewById(R.id.tv_oil_price_ninety_seven);
        mTv_oil_price_ninety_three = (TextView) mInflate.findViewById(R.id.tv_oil_price_ninety_three);
        mTv_oil_price_ninety = (TextView) mInflate.findViewById(R.id.tv_oil_price_ninety);
        mTv_oil_price_zero = (TextView) mInflate.findViewById(R.id.tv_oil_price_zero);
    }

    private void setListener()
    {
        mIv_qicheguanjia_back.setOnClickListener(this);
        mInflate.findViewById(R.id.ll_rela_zijiazuche).setOnClickListener(this);
        mInflate.findViewById(R.id.ll_rela_jigouyongche).setOnClickListener(this);
    }

    private void initUI()
    {
        //TODO  -------
    }

    @Override
    public void onClick(View v)
    {
        Intent intent = new Intent();
        switch (v.getId())
        {
            case R.id.iv_qicheguanjia_back:
                getActivity().finish();
                animFromBigToSmallOUT();
                break;
            case R.id.ll_rela_zijiazuche:
                intent.setClass(getActivity(), ZiJiaZuCheActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_rela_jigouyongche:
                intent.setClass(getActivity(), ZuChenJiGouYongCheActivity.class);
                startActivity(intent);
                break;
        }
    }

    /**
     * 从大到小结束动画
     */
    private void animFromBigToSmallOUT()
    {
        getActivity().overridePendingTransition(R.anim.fade_in, R.anim.big_to_small_fade_out);
    }

}
